package org.example.exception;

import cn.dev33.satoken.util.SaResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Configuration
public class GlobalExceptionHandler {
    private static final Logger LOGGER = LoggerFactory.getLogger(GlobalExceptionHandler.class);
    
    @ExceptionHandler(BizException.class)
    public SaResult bizExceptionHandler(BizException e) {
        String message = e.getMessage();
        return SaResult.error(message);
    }

    @ExceptionHandler(Exception.class)
    public SaResult exceptionHandler(Exception e) {
        LOGGER.error(e.getMessage());
        e.printStackTrace();
        String message = e.getMessage();
        return SaResult.error(message);
    }
}
